package com.lyf.scm.admin.domain.remote.allocationservice.facade;


import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.*;
import com.lyf.scm.admin.domain.excel.dto.SalesWriteDTO;
import com.lyf.scm.admin.domain.remote.allocationservice.SalesPlanOtherRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * description:
 * 其他渠道计划正面
 *
 * @author: huangtao
 * @data: 2020/7/31
 */
@Service
@Slf4j
public class SalesPlanOtherFacade {

    @Resource
    private SalesPlanOtherRemote salesPlanOtherRemote;

    /**
     * 按条件查询其他渠道计划(周)
     *
     * @param salesPlanOther
     * @return
     */
    /*public PageInfo<SalesPlanOtherInfoDTO> listWeekBySelective(SalesPlanOtherDTO salesPlanOther) {
        log.info("其他渠道计划明细信息入参:salesPlanOther:{}", salesPlanOther);
        Response<PageInfo<SalesPlanOtherInfoDTO>> response = salesPlanOtherRemote.listWeekBySelective(salesPlanOther);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }*/

    /**
     * 查询其他渠道计划(范围)
     *
     * @param salesPlanOther
     * @return
     */
    /*public List<SalesPlanOtherInfoDTO> listAllByCycles(SalesPlanOtherDTO salesPlanOther) {
        log.info("其他渠道计划(范围)明细信息入参:salesPlanOther:{}", salesPlanOther);
        Response<List<SalesPlanOtherInfoDTO>> response = salesPlanOtherRemote.listAllByCycles(salesPlanOther);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }*/

    /**
     * 其他渠道计划导入
     *
     * @param dtoList
     * @param impType 1：销售计划，2：新开店计划，3：新品铺货计划
     * @param id 操作日志表Id
     * @return
     */
    public Integer importPlanType(List<SalesPlanOtherDTO> dtoList, Integer impType, Long id) {
        log.info("其他渠道计划导入条数:size:{}", dtoList.size() + "条");
        Response<Integer> response = salesPlanOtherRemote.importPlanType(dtoList, impType, id);
        if (!ResponseMsg.SUCCESS.getCode().equals(response.getCode())) {
            log.error("其他渠道计划导入失败:dtoList,impType:{}", dtoList + ",", impType + ",", id);
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 更新确认量
     *
     * @param all
     * @param unitType
     * @param userId
     */
    public Boolean confirm(List<SalesPlanOtherDTO> all, Long unitType, Integer level) {
        log.info("其他渠道计划更新确认量:all,unitType,level:{}", all + ",", unitType + ",", level);
        Response<Boolean> response = salesPlanOtherRemote.confirm(all, unitType, level);
        if (!ResponseMsg.SUCCESS.getCode().equals(response.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /*public Integer getOtherPlanLevel(Long userId) {
        log.info("其他渠道计划获取当前用户级别:userId:{}", userId);
        Response<Integer> response = salesPlanOtherRemote.getOtherPlanLevel(userId);
        if (!ResponseMsg.SUCCESS.getCode().equals(response.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }*/

    /**
     * 导出
     *
     * @param salesPlanOtherDTO
     * @param type
     * @return
     */
    public feign.Response export(SalesPlanOtherDTO salesPlanOtherDTO, Integer type) {
        log.info("其他渠道计划导出:salesPlanOtherDTO,type:{}", salesPlanOtherDTO + ",", type);
        return salesPlanOtherRemote.export(salesPlanOtherDTO, type);
    }

    /**
     * 导出模板
     *
     * @param type
     * @param date
     * @return
     */
    public feign.Response downLoadTemplate(String type, String date) {
        log.info("其他渠道计划导出模板:salesPlanOtherDTO,type:{}", type);
        return salesPlanOtherRemote.downLoadTemplate(type, date);
    }


    public void delete(String opSign) {
        log.info("删除其他渠道计划:{}", JSON.toJSONString(opSign));
        salesPlanOtherRemote.delete(opSign);
    }

    public List<SalesWriteDTO> getLastWeekByType() {
        Response<List<SalesWriteDTO>> response = salesPlanOtherRemote.getLastWeekByType();
        if (!ResponseMsg.SUCCESS.getCode().equals(response.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }
}